#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：henan_sumo
@File ：config40.py
@IDE ：PyCharm
@Author ：xinyingjie
@Date ：2025/5/13 8:52
'''

from utils.tools import calculate_distance

USE_LIBSUMO = True
USE_GUI = False
SHOW_SIMU = True
# KAFKA_HOST = '172.20.8.74:59092'
KAFKA_HOST = '10.102.1.158:9092'
KAFKA_SEND_TOPIC = "e1_fusion_data_v4"
KAFKA_RECEIVE_TOPIC = "e1_kako_data"

KAFKA_E1_TOPIC = "40km_leida_data_sumo"
KAFKA_E1_TOPIC_SIMU = "e1_fusion_data_v1"

KAFKA_STATUS = "device_up_status"
# RADAR_DATA_LIST = {'S_1': {'sn': 'S_1', 'lat': 29.34165067, 'lon': 107.75162951, 'direct': 1, 'drive_distance': 1000,
#                            'Downstream': {'sn': 'S_2'}, 'Upstream': None, 'disDown': 1000, 'normal': True},
#                    'X_1': {'sn': 'X_1', 'lat': 29.3392867, 'lon': 107.36530849, 'direct': 2, 'drive_distance': 1000,
#                            'Downstream': {'sn': 'X_2'}, 'Upstream': None, 'disDown': 1000, 'normal': True},
#                    'S_2': {'sn': 'S_2', 'lat': 29.3453687, 'lon': 107.74224661, 'direct': 1, 'drive_distance': 2000,
#                            'Downstream': {'sn': 'S_3'}, 'Upstream': {'sn': 'S_1'}, 'disDown': 1000, 'normal': True},
#                    'X_2': {'sn': 'X_2', 'lat': 29.33872115, 'lon': 107.37556106, 'direct': 2, 'drive_distance': 2000,
#                            'Downstream': {'sn': 'X_3'}, 'Upstream': {'sn': 'X_1'}, 'disDown': 1000, 'normal': True},
#                    'S_3': {'sn': 'S_3', 'lat': 29.34909288, 'lon': 107.73286834, 'direct': 1, 'drive_distance': 3000,
#                            'Downstream': {'sn': 'S_4'}, 'Upstream': {'sn': 'S_2'}, 'disDown': 1000, 'normal': True},
#                    'X_3': {'sn': 'X_3', 'lat': 29.33768012, 'lon': 107.38578912, 'direct': 2, 'drive_distance': 3000,
#                            'Downstream': {'sn': 'X_4'}, 'Upstream': {'sn': 'X_2'}, 'disDown': 1000, 'normal': True},
#                    'S_4': {'sn': 'S_4', 'lat': 29.35175147, 'lon': 107.72304797, 'direct': 1, 'drive_distance': 4000,
#                            'Downstream': {'sn': 'S_5'}, 'Upstream': {'sn': 'S_3'}, 'disDown': 1000, 'normal': True},
#                    'X_4': {'sn': 'X_4', 'lat': 29.33663246, 'lon': 107.39601542, 'direct': 2, 'drive_distance': 4000,
#                            'Downstream': {'sn': 'X_5'}, 'Upstream': {'sn': 'X_3'}, 'disDown': 1000, 'normal': True},
#                    'S_5': {'sn': 'S_5', 'lat': 29.35427181, 'lon': 107.71317135, 'direct': 1, 'drive_distance': 5000,
#                            'Downstream': {'sn': 'S_6'}, 'Upstream': {'sn': 'S_4'}, 'disDown': 1000, 'normal': True},
#                    'X_5': {'sn': 'X_5', 'lat': 29.33558939, 'lon': 107.40624318, 'direct': 2, 'drive_distance': 5000,
#                            'Downstream': {'sn': 'X_6'}, 'Upstream': {'sn': 'X_4'}, 'disDown': 1000, 'normal': True},
#                    'S_6': {'sn': 'S_6', 'lat': 29.3574628, 'lon': 107.70353065, 'direct': 1, 'drive_distance': 6000,
#                            'Downstream': {'sn': 'S_7'}, 'Upstream': {'sn': 'S_5'}, 'disDown': 1000, 'normal': True},
#                    'X_6': {'sn': 'X_6', 'lat': 29.33455723, 'lon': 107.41646554, 'direct': 2, 'drive_distance': 6000,
#                            'Downstream': {'sn': 'X_7'}, 'Upstream': {'sn': 'X_5'}, 'disDown': 1000, 'normal': True},
#                    'S_7': {'sn': 'S_7', 'lat': 29.35950635, 'lon': 107.69350448, 'direct': 1, 'drive_distance': 7000,
#                            'Downstream': {'sn': 'S_8'}, 'Upstream': {'sn': 'S_6'}, 'disDown': 1000, 'normal': True},
#                    'X_7': {'sn': 'X_7', 'lat': 29.33351694, 'lon': 107.42669244, 'direct': 2, 'drive_distance': 7000,
#                            'Downstream': {'sn': 'X_8'}, 'Upstream': {'sn': 'X_6'}, 'disDown': 1000, 'normal': True},
#                    'S_8': {'sn': 'S_8', 'lat': 29.36170224, 'lon': 107.6835332, 'direct': 1, 'drive_distance': 8000,
#                            'Downstream': {'sn': 'S_9'}, 'Upstream': {'sn': 'S_7'}, 'disDown': 1000, 'normal': True},
#                    'X_8': {'sn': 'X_8', 'lat': 29.33247374, 'lon': 107.4369204, 'direct': 2, 'drive_distance': 8000,
#                            'Downstream': {'sn': 'X_9'}, 'Upstream': {'sn': 'X_7'}, 'disDown': 1000, 'normal': True},
#                    'S_9': {'sn': 'S_9', 'lat': 29.36723553, 'lon': 107.67545559, 'direct': 1, 'drive_distance': 9000,
#                            'Downstream': {'sn': 'S_10'}, 'Upstream': {'sn': 'S_8'}, 'disDown': 1000, 'normal': True},
#                    'X_9': {'sn': 'X_9', 'lat': 29.33379068, 'lon': 107.44688512, 'direct': 2, 'drive_distance': 9000,
#                            'Downstream': {'sn': 'X_10'}, 'Upstream': {'sn': 'X_8'}, 'disDown': 1000, 'normal': True},
#                    'S_10': {'sn': 'S_10', 'lat': 29.37234525, 'lon': 107.6670209, 'direct': 1, 'drive_distance': 10000,
#                             'Downstream': {'sn': 'S_11'}, 'Upstream': {'sn': 'S_9'}, 'disDown': 1000, 'normal': True},
#                    'X_10': {'sn': 'X_10', 'lat': 29.33692934, 'lon': 107.45640237, 'direct': 2, 'drive_distance': 10000,
#                             'Downstream': {'sn': 'X_11'}, 'Upstream': {'sn': 'X_9'}, 'disDown': 1000, 'normal': True},
#                    'S_11': {'sn': 'S_11', 'lat': 29.37509313, 'lon': 107.65721533, 'direct': 1, 'drive_distance': 11000,
#                             'Downstream': {'sn': 'S_12'}, 'Upstream': {'sn': 'S_10'}, 'disDown': 1000, 'normal': True},
#                    'X_11': {'sn': 'X_11', 'lat': 29.34046396, 'lon': 107.46569889, 'direct': 2, 'drive_distance': 11000,
#                             'Downstream': {'sn': 'X_12'}, 'Upstream': {'sn': 'X_10'}, 'disDown': 1000, 'normal': True},
#                    'S_12': {'sn': 'S_12', 'lat': 29.3776851, 'lon': 107.64734922, 'direct': 1, 'drive_distance': 12000,
#                             'Downstream': {'sn': 'S_13'}, 'Upstream': {'sn': 'S_11'}, 'disDown': 1000, 'normal': True},
#                    'X_12': {'sn': 'X_12', 'lat': 29.34630967, 'lon': 107.47351687, 'direct': 2, 'drive_distance': 12000,
#                             'Downstream': {'sn': 'X_13'}, 'Upstream': {'sn': 'X_11'}, 'disDown': 1000, 'normal': True},
#                    'S_13': {'sn': 'S_13', 'lat': 29.37997444, 'lon': 107.63739719, 'direct': 1, 'drive_distance': 13000,
#                             'Downstream': {'sn': 'S_14'}, 'Upstream': {'sn': 'S_12'}, 'disDown': 1000, 'normal': True},
#                    'X_13': {'sn': 'X_13', 'lat': 29.35310012, 'lon': 107.48029562, 'direct': 2, 'drive_distance': 13000,
#                             'Downstream': {'sn': 'X_14'}, 'Upstream': {'sn': 'X_12'}, 'disDown': 1000, 'normal': True},
#                    'S_14': {'sn': 'S_14', 'lat': 29.380134, 'lon': 107.62711881, 'direct': 1, 'drive_distance': 14000,
#                             'Downstream': {'sn': 'S_15'}, 'Upstream': {'sn': 'S_13'}, 'disDown': 1000, 'normal': True},
#                    'X_14': {'sn': 'X_14', 'lat': 29.36164235, 'lon': 107.48251229, 'direct': 2, 'drive_distance': 14000,
#                             'Downstream': {'sn': 'X_15'}, 'Upstream': {'sn': 'X_13'}, 'disDown': 1000, 'normal': True},
#                    'S_15': {'sn': 'S_15', 'lat': 29.37976171, 'lon': 107.61682634, 'direct': 1, 'drive_distance': 15000,
#                             'Downstream': {'sn': 'S_16'}, 'Upstream': {'sn': 'S_14'}, 'disDown': 1000, 'normal': True},
#                    'X_15': {'sn': 'X_15', 'lat': 29.36905188, 'lon': 107.48776423, 'direct': 2, 'drive_distance': 15000,
#                             'Downstream': {'sn': 'X_16'}, 'Upstream': {'sn': 'X_14'}, 'disDown': 1000, 'normal': True},
#                    'S_16': {'sn': 'S_16', 'lat': 29.37938646, 'lon': 107.60653413, 'direct': 1, 'drive_distance': 16000,
#                             'Downstream': {'sn': 'S_17'}, 'Upstream': {'sn': 'S_15'}, 'disDown': 1000, 'normal': True},
#                    'X_16': {'sn': 'X_16', 'lat': 29.37379782, 'lon': 107.49645699, 'direct': 2, 'drive_distance': 16000,
#                             'Downstream': {'sn': 'X_17'}, 'Upstream': {'sn': 'X_15'}, 'disDown': 1000, 'normal': True},
#                    'S_17': {'sn': 'S_17', 'lat': 29.37901034, 'lon': 107.59624277, 'direct': 1, 'drive_distance': 17000,
#                             'Downstream': {'sn': 'S_18'}, 'Upstream': {'sn': 'S_16'}, 'disDown': 1000, 'normal': True},
#                    'X_17': {'sn': 'X_17', 'lat': 29.37525377, 'lon': 107.50609022, 'direct': 2, 'drive_distance': 17000,
#                             'Downstream': {'sn': 'X_18'}, 'Upstream': {'sn': 'X_16'}, 'disDown': 1000, 'normal': True},
#                    'S_18': {'sn': 'S_18', 'lat': 29.37863262, 'lon': 107.58595093, 'direct': 1, 'drive_distance': 18000,
#                             'Downstream': {'sn': 'S_19'}, 'Upstream': {'sn': 'S_17'}, 'disDown': 1000, 'normal': True},
#                    'X_18': {'sn': 'X_18', 'lat': 29.37470981, 'lon': 107.51626513, 'direct': 2, 'drive_distance': 18000,
#                             'Downstream': {'sn': 'X_19'}, 'Upstream': {'sn': 'X_17'}, 'disDown': 1000, 'normal': True},
#                    'S_19': {'sn': 'S_19', 'lat': 29.37825632, 'lon': 107.57566017, 'direct': 1, 'drive_distance': 19000,
#                             'Downstream': {'sn': 'S_20'}, 'Upstream': {'sn': 'S_18'}, 'disDown': 1000, 'normal': True},
#                    'X_19': {'sn': 'X_19', 'lat': 29.37435755, 'lon': 107.52648496, 'direct': 2, 'drive_distance': 19000,
#                             'Downstream': {'sn': 'X_20'}, 'Upstream': {'sn': 'X_18'}, 'disDown': 1000, 'normal': True},
#                    'S_20': {'sn': 'S_20', 'lat': 29.37787623, 'lon': 107.56536886, 'direct': 1, 'drive_distance': 20000,
#                             'Downstream': {'sn': 'S_21'}, 'Upstream': {'sn': 'S_19'}, 'disDown': 1000, 'normal': True},
#                    'X_20': {'sn': 'X_20', 'lat': 29.37483747, 'lon': 107.53669751, 'direct': 2, 'drive_distance': 20000,
#                             'Downstream': {'sn': 'X_21'}, 'Upstream': {'sn': 'X_19'}, 'disDown': 1000, 'normal': True},
#                    'S_21': {'sn': 'S_21', 'lat': 29.37749547, 'lon': 107.55507633, 'direct': 1, 'drive_distance': 21000,
#                             'Downstream': {'sn': 'S_22'}, 'Upstream': {'sn': 'S_20'}, 'disDown': 1000, 'normal': True},
#                    'X_21': {'sn': 'X_21', 'lat': 29.37641115, 'lon': 107.54683946, 'direct': 2, 'drive_distance': 21000,
#                             'Downstream': {'sn': 'X_22'}, 'Upstream': {'sn': 'X_20'}, 'disDown': 1000, 'normal': True},
#                    'S_22': {'sn': 'S_22', 'lat': 29.37648006, 'lon': 107.54485688, 'direct': 1, 'drive_distance': 22000,
#                             'Downstream': {'sn': 'S_23'}, 'Upstream': {'sn': 'S_21'}, 'disDown': 1000, 'normal': True},
#                    'X_22': {'sn': 'X_22', 'lat': 29.37709192, 'lon': 107.55710173, 'direct': 2, 'drive_distance': 22000,
#                             'Downstream': {'sn': 'X_23'}, 'Upstream': {'sn': 'X_21'}, 'disDown': 1000, 'normal': True},
#                    'S_23': {'sn': 'S_23', 'lat': 29.37490269, 'lon': 107.53471436, 'direct': 1, 'drive_distance': 23000,
#                             'Downstream': {'sn': 'S_24'}, 'Upstream': {'sn': 'S_22'}, 'disDown': 1000, 'normal': True},
#                    'X_23': {'sn': 'X_23', 'lat': 29.37747575, 'lon': 107.56738444, 'direct': 2, 'drive_distance': 23000,
#                             'Downstream': {'sn': 'X_24'}, 'Upstream': {'sn': 'X_22'}, 'disDown': 1000, 'normal': True},
#                    'S_24': {'sn': 'S_24', 'lat': 29.3748431, 'lon': 107.52454838, 'direct': 1, 'drive_distance': 24000,
#                             'Downstream': {'sn': 'S_25'}, 'Upstream': {'sn': 'S_23'}, 'disDown': 1000, 'normal': True},
#                    'X_24': {'sn': 'X_24', 'lat': 29.37785983, 'lon': 107.57767594, 'direct': 2, 'drive_distance': 24000,
#                             'Downstream': {'sn': 'X_25'}, 'Upstream': {'sn': 'X_23'}, 'disDown': 1000, 'normal': True},
#                    'S_25': {'sn': 'S_25', 'lat': 29.37466637, 'lon': 107.51428693, 'direct': 1, 'drive_distance': 25000,
#                             'Downstream': {'sn': 'S_26'}, 'Upstream': {'sn': 'S_24'}, 'disDown': 1000, 'normal': True},
#                    'X_25': {'sn': 'X_25', 'lat': 29.37823745, 'lon': 107.58797605, 'direct': 2, 'drive_distance': 25000,
#                             'Downstream': {'sn': 'X_26'}, 'Upstream': {'sn': 'X_24'}, 'disDown': 1000, 'normal': True},
#                    'S_26': {'sn': 'S_26', 'lat': 29.37580273, 'lon': 107.50415617, 'direct': 1, 'drive_distance': 26000,
#                             'Downstream': {'sn': 'S_27'}, 'Upstream': {'sn': 'S_25'}, 'disDown': 1000, 'normal': True},
#                    'X_26': {'sn': 'X_26', 'lat': 29.37861622, 'lon': 107.59825878, 'direct': 2, 'drive_distance': 26000,
#                             'Downstream': {'sn': 'X_27'}, 'Upstream': {'sn': 'X_25'}, 'disDown': 1000, 'normal': True},
#                    'S_27': {'sn': 'S_27', 'lat': 29.37279637, 'lon': 107.49492218, 'direct': 1, 'drive_distance': 27000,
#                             'Downstream': {'sn': 'S_28'}, 'Upstream': {'sn': 'S_26'}, 'disDown': 1000, 'normal': True},
#                    'X_27': {'sn': 'X_27', 'lat': 29.37899968, 'lon': 107.60854992, 'direct': 2, 'drive_distance': 27000,
#                             'Downstream': {'sn': 'X_28'}, 'Upstream': {'sn': 'X_26'}, 'disDown': 1000, 'normal': True},
#                    'S_28': {'sn': 'S_28', 'lat': 29.36813312, 'lon': 107.48615696, 'direct': 1, 'drive_distance': 28000,
#                             'Downstream': {'sn': 'S_29'}, 'Upstream': {'sn': 'S_27'}, 'disDown': 1000, 'normal': True},
#                    'X_28': {'sn': 'X_28', 'lat': 29.37939381, 'lon': 107.6188416, 'direct': 2, 'drive_distance': 28000,
#                             'Downstream': {'sn': 'X_29'}, 'Upstream': {'sn': 'X_27'}, 'disDown': 1000, 'normal': True},
#                    'S_29': {'sn': 'S_29', 'lat': 29.36007721, 'lon': 107.48231347, 'direct': 1, 'drive_distance': 29000,
#                             'Downstream': {'sn': 'S_30'}, 'Upstream': {'sn': 'S_28'}, 'disDown': 1000, 'normal': True},
#                    'X_29': {'sn': 'X_29', 'lat': 29.37979964, 'lon': 107.62913959, 'direct': 2, 'drive_distance': 29000,
#                             'Downstream': {'sn': 'X_30'}, 'Upstream': {'sn': 'X_28'}, 'disDown': 1000, 'normal': True},
#                    'S_30': {'sn': 'S_30', 'lat': 29.35193198, 'lon': 107.47895077, 'direct': 1, 'drive_distance': 30000,
#                             'Downstream': {'sn': 'S_31'}, 'Upstream': {'sn': 'S_29'}, 'disDown': 1000, 'normal': True},
#                    'X_30': {'sn': 'X_30', 'lat': 29.37928014, 'lon': 107.63938885, 'direct': 2, 'drive_distance': 30000,
#                             'Downstream': {'sn': 'X_31'}, 'Upstream': {'sn': 'X_29'}, 'disDown': 1000, 'normal': True},
#                    'S_31': {'sn': 'S_31', 'lat': 29.34528454, 'lon': 107.47198694, 'direct': 1, 'drive_distance': 31000,
#                             'Downstream': {'sn': 'S_32'}, 'Upstream': {'sn': 'S_30'}, 'disDown': 1000, 'normal': True},
#                    'X_31': {'sn': 'X_31', 'lat': 29.37679287, 'lon': 107.64927948, 'direct': 2, 'drive_distance': 31000,
#                             'Downstream': {'sn': 'X_32'}, 'Upstream': {'sn': 'X_30'}, 'disDown': 1000, 'normal': True},
#                    'S_32': {'sn': 'S_32', 'lat': 29.33970104, 'lon': 107.46389998, 'direct': 1, 'drive_distance': 32000,
#                             'Downstream': {'sn': 'S_33'}, 'Upstream': {'sn': 'S_31'}, 'disDown': 1000, 'normal': True},
#                    'X_32': {'sn': 'X_32', 'lat': 29.37420133, 'lon': 107.65914475, 'direct': 2, 'drive_distance': 32000,
#                             'Downstream': {'sn': 'X_33'}, 'Upstream': {'sn': 'X_31'}, 'disDown': 1000, 'normal': True},
#                    'S_33': {'sn': 'S_33', 'lat': 29.33667161, 'lon': 107.45436247, 'direct': 1, 'drive_distance': 33000,
#                             'Downstream': {'sn': 'S_34'}, 'Upstream': {'sn': 'S_32'}, 'disDown': 1000, 'normal': True},
#                    'X_33': {'sn': 'X_33', 'lat': 29.37122679, 'lon': 107.66885922, 'direct': 2, 'drive_distance': 33000,
#                             'Downstream': {'sn': 'X_34'}, 'Upstream': {'sn': 'X_32'}, 'disDown': 1000, 'normal': True},
#                    'S_34': {'sn': 'S_34', 'lat': 29.33324104, 'lon': 107.44493664, 'direct': 1, 'drive_distance': 34000,
#                             'Downstream': {'sn': 'S_35'}, 'Upstream': {'sn': 'S_33'}, 'disDown': 1000, 'normal': True},
#                    'X_34': {'sn': 'X_34', 'lat': 29.36574968, 'lon': 107.67689853, 'direct': 2, 'drive_distance': 34000,
#                             'Downstream': {'sn': 'X_35'}, 'Upstream': {'sn': 'X_33'}, 'disDown': 1000, 'normal': True},
#                    'S_35': {'sn': 'S_35', 'lat': 29.33306099, 'lon': 107.43476246, 'direct': 1, 'drive_distance': 35000,
#                             'Downstream': {'sn': 'S_36'}, 'Upstream': {'sn': 'S_34'}, 'disDown': 1000, 'normal': True},
#                    'X_35': {'sn': 'X_35', 'lat': 29.36076319, 'lon': 107.68533315, 'direct': 2, 'drive_distance': 35000,
#                             'Downstream': {'sn': 'X_36'}, 'Upstream': {'sn': 'X_34'}, 'disDown': 1000, 'normal': True},
#                    'S_36': {'sn': 'S_36', 'lat': 29.33410324, 'lon': 107.42453587, 'direct': 1, 'drive_distance': 36000,
#                             'Downstream': {'sn': 'S_37'}, 'Upstream': {'sn': 'S_35'}, 'disDown': 1000, 'normal': True},
#                    'X_36': {'sn': 'X_36', 'lat': 29.35881447, 'lon': 107.69538615, 'direct': 2, 'drive_distance': 36000,
#                             'Downstream': {'sn': 'X_37'}, 'Upstream': {'sn': 'X_35'}, 'disDown': 1000, 'normal': True},
#                    'S_37': {'sn': 'S_37', 'lat': 29.33515625, 'lon': 107.41431009, 'direct': 1, 'drive_distance': 37000,
#                             'Downstream': {'sn': 'S_38'}, 'Upstream': {'sn': 'S_36'}, 'disDown': 1000, 'normal': True},
#                    'X_37': {'sn': 'X_37', 'lat': 29.35675308, 'lon': 107.70540665, 'direct': 2, 'drive_distance': 37000,
#                             'Downstream': {'sn': 'X_38'}, 'Upstream': {'sn': 'X_36'}, 'disDown': 1000, 'normal': True},
#                    'S_38': {'sn': 'S_38', 'lat': 29.33620033, 'lon': 107.40408198, 'direct': 1, 'drive_distance': 38000,
#                             'Downstream': {'sn': 'S_39'}, 'Upstream': {'sn': 'S_37'}, 'disDown': 1000, 'normal': True},
#                    'X_38': {'sn': 'X_38', 'lat': 29.35348885, 'lon': 107.71500025, 'direct': 2, 'drive_distance': 38000,
#                             'Downstream': {'sn': 'X_39'}, 'Upstream': {'sn': 'X_37'}, 'disDown': 1000, 'normal': True},
#                    'S_39': {'sn': 'S_39', 'lat': 29.33723529, 'lon': 107.39385326, 'direct': 1, 'drive_distance': 39000,
#                             'Downstream': {'sn': 'S_40'}, 'Upstream': {'sn': 'S_38'}, 'disDown': 1000, 'normal': True},
#                    'X_39': {'sn': 'X_39', 'lat': 29.35097114, 'lon': 107.72487731, 'direct': 2, 'drive_distance': 39000,
#                             'Downstream': {'sn': 'X_40'}, 'Upstream': {'sn': 'X_38'}, 'disDown': 1000, 'normal': True},
#                    'S_40': {'sn': 'S_40', 'lat': 29.33827163, 'lon': 107.38362548, 'direct': 1, 'drive_distance': 40000,
#                             'Downstream': {'sn': 'S_41'}, 'Upstream': {'sn': 'S_39'}, 'disDown': 1000, 'normal': True},
#                    'X_40': {'sn': 'X_40', 'lat': 29.34800422, 'lon': 107.73457472, 'direct': 2, 'drive_distance': 40000,
#                             'Downstream': {'sn': 'X_41'}, 'Upstream': {'sn': 'X_39'}, 'disDown': 1000, 'normal': True},
#                    'S_41': {'sn': 'S_41', 'lat': 29.33931185, 'lon': 107.37339846, 'direct': 1, 'drive_distance': 41000,
#                             'Downstream': {'sn': 'S_42'}, 'Upstream': {'sn': 'S_40'}, 'disDown': 1000, 'normal': True},
#                    'X_41': {'sn': 'X_41', 'lat': 29.34428955, 'lon': 107.74395733, 'direct': 2, 'drive_distance': 41000,
#                             'Downstream': {'sn': 'X_42'}, 'Upstream': {'sn': 'X_40'}, 'disDown': 1000, 'normal': True},
#                    'S_42': {'sn': 'S_42', 'lat': 29.33926273, 'lon': 107.3631556, 'direct': 1, 'drive_distance': 42000,
#                             'Downstream': None, 'Upstream': {'sn': 'S_41'}, 'disDown': 1000, 'normal': True},
#                    'X_42': {'sn': 'X_42', 'lat': 29.3405708, 'lon': 107.75333882, 'direct': 2, 'drive_distance': 42000,
#                             'Downstream': None, 'Upstream': {'sn': 'X_41'}, 'disDown': 1000, 'normal': True}}

RADAR_DATA_LIST = {
    "1": {"sn": "1", "lat": 29.34239708, "lon": 107.74974517, "direct": 1, "drive_distance": 1200,
          "Downstream": {"sn": "2"}, "Upstream": None, "disDown": 600, "normal": True,'have_plate':True},
    "2": {"sn": "2", "lat": 29.34462713, "lon": 107.74411579, "direct": 1, "drive_distance": 1800,
          "Downstream": {"sn": "3"}, "Upstream": {"sn": "1"}, "disDown": 600, "normal": True,'have_plate':False},
    "3": {"sn": "3", "lat": 29.34686142, "lon": 107.73848711, "direct": 1, "drive_distance": 2400,
          "Downstream": {"sn": "4"}, "Upstream": {"sn": "2"}, "disDown": 600, "normal": True,'have_plate':False},
    "4": {"sn": "4", "lat": 29.34909924, "lon": 107.73285226, "direct": 1, "drive_distance": 3000,
          "Downstream": {"sn": "5"}, "Upstream": {"sn": "3"}, "disDown": 600, "normal": True,'have_plate':True},
    "5": {"sn": "5", "lat": 29.35087627, "lon": 107.72703522, "direct": 1, "drive_distance": 3600,
          "Downstream": {"sn": "6"}, "Upstream": {"sn": "4"}, "disDown": 600, "normal": True,'have_plate':False},
    "6": {"sn": "6", "lat": 29.35219424, "lon": 107.72103379, "direct": 1, "drive_distance": 4200,
          "Downstream": {"sn": "7"}, "Upstream": {"sn": "5"}, "disDown": 600, "normal": True,'have_plate':False},
    "7": {"sn": "7", "lat": 29.35364542, "lon": 107.7150925, "direct": 1, "drive_distance": 4800,
          "Downstream": {"sn": "8"}, "Upstream": {"sn": "6"}, "disDown": 600, "normal": True,'have_plate':False},
    "8": {"sn": "8", "lat": 29.35558299, "lon": 107.70931022, "direct": 1, "drive_distance": 5400,
          "Downstream": {"sn": "9"}, "Upstream": {"sn": "7"}, "disDown": 600, "normal": True,'have_plate':True},
    "9": {"sn": "9", "lat": 29.35746981, "lon": 107.70350468, "direct": 1, "drive_distance": 6000,
          "Downstream": {"sn": "10"}, "Upstream": {"sn": "8"}, "disDown": 600, "normal": True,'have_plate':False},
    "10": {"sn": "10", "lat": 29.35875599, "lon": 107.69750646, "direct": 1, "drive_distance": 6600,
           "Downstream": {"sn": "11"}, "Upstream": {"sn": "9"}, "disDown": 600, "normal": True,'have_plate':False},
    "11": {"sn": "11", "lat": 29.35988891, "lon": 107.69146351, "direct": 1, "drive_distance": 7200,
           "Downstream": {"sn": "12"}, "Upstream": {"sn": "10"}, "disDown": 600, "normal": True,'have_plate':False},
    "12": {"sn": "12", "lat": 29.36107945, "lon": 107.68544578, "direct": 1, "drive_distance": 7800,
           "Downstream": {"sn": "13"}, "Upstream": {"sn": "11"}, "disDown": 600, "normal": True,'have_plate':False},
    "13": {"sn": "13", "lat": 29.36361127, "lon": 107.68003044, "direct": 1, "drive_distance": 8400,
           "Downstream": {"sn": "14"}, "Upstream": {"sn": "12"}, "disDown": 600, "normal": True,'have_plate':True},
    "14": {"sn": "14", "lat": 29.36724645, "lon": 107.67544191, "direct": 1, "drive_distance": 9000,
           "Downstream": {"sn": "15"}, "Upstream": {"sn": "13"}, "disDown": 600, "normal": True,'have_plate':False},
    "15": {"sn": "15", "lat": 29.37065694, "lon": 107.67063326, "direct": 1, "drive_distance": 9600,
           "Downstream": None, "Upstream": {"sn": "14"}, "disDown": 600, "normal": True,'have_plate':True}
}

# 全局中心点
GLOBAL_POLYGON_CENTER = [(4448.62, 202.30), (4408.84, 896.84),
                         (3674.53, 890.73), (3738.78, -76.12)]

MAX_SPEED = int(150 / 3.6)
MIN_SPEED = int(30 / 3.6)
CAR_DEFAULT_SPEED = 24
TRUCK_DEFAULT_SPEED = 20
SPECIAL_DEFAULT_SPEED = 18
# 经度逐渐减少
# 感知 第一种出现位置直接发车
# 第二个门架位置进行删车操作

erId_dict = {
    "S001933030055210010": {"lon": 121.159129, "lat": 28.23522},
    "S001933030055210011": {"lon": 121.154497, "lat": 28.238024},  # 删除  all-data没有上报这条数据，就删除
    "S001933030055210012": {"lon": 121.15025, "lat": 28.239659},
    "S001933030055210013": {"lon": 121.144683, "lat": 28.241137},
    "S001933030055210014": {"lon": 121.139778, "lat": 28.24239},
    "S001933030055210015": {"lon": 121.135468, "lat": 28.243534},
    "S001933030055210016": {"lon": 121.128253, "lat": 28.244775},
    "S001933030055210017": {"lon": 121.124437, "lat": 28.244834}}

type_change = {1: 1, 2: 12, 3: 3}
# route_list = ['-6', '-3', '-14', '-0', '-7', '-2', '-11', '-13', '-10', '-5', '-9', '-8', '-1']
route_list = {
    "0": [
        ['80', '74', '9', '85', '84', '-51', '-16', '-10', '-91', '-92', '-105', '-106'],
        ['80', '74', '9', '85', '88', '-44', '-6', '-65', '-92', '-105', '-106'],
        ['80', '74', '9', '13', '12', '-60', '-34', '-41', '-14', '-106'],
        ['80', '74', '9', '13', '-26', '-45', '-41', '-14', '-106'],
    ],
    "1": [
        ['25', '55', '109', '37', '36', '-108', '-27', '-11', '-53', '-66', '-99', '-83'],
        ['25', '55', '109', '37', '-102', '-75', '-11', '-53', '-66', '-99', '-83'],
        ['25', '55', '109', '81', '72', '71', '-21', '-33', '-2', '-3', '-66', '-99', '-83'],
        ['25', '55', '109', '81', '72', '24', '-93', '-94', '-3', '-66', '-99', '-83'],
    ],
    "2": [
        ['18', '17', '70', '69', '-39', '-57', '-63', '-64', '-96', '-97', '-48', '-47'],
        ['18', '17', '70', '59', '-38', '-101', '-76', '-64', '-96', '-97', '-48', '-47'],
        ['18', '79', '104', '-90', '-46', '-42', '-43', '-97', '-48', '-47'],
        ['18', '79', '104', '68', '73', '-28', '-61', '-0', '-43', '-97', '-48', '-47'],
        ['18', '29', '77', '-22', '-103', '-19', '-30', '-31', '-58', '-97', '-48', '-47'],
        ['18', '29', '77', '-89', '-35', '-40', '-32', '-31', '-58', '-97', '-48', '-47'],
        ['18', '29', '77', '-100', '-82', '-54', '-78', '-31', '-58', '-97', '-48', '-47'],
    ],
}

if __name__ == '__main__':
    # print(list(RADAR_DATA_LIST.keys()))
    # for sn in list(RADAR_DATA_LIST.keys()):
    #     one = RADAR_DATA_LIST[sn]
    #     if one['Downstream']:
    #         print(one['lon'], one['lat'], RADAR_DATA_LIST[one['Downstream']['sn']]['lon'],
    #               RADAR_DATA_LIST[one['Downstream']['sn']]['lat'])
    #         print(calculate_distance(one['lon'], one['lat'], RADAR_DATA_LIST[one['Downstream']['sn']]['lon'],
    #                                  RADAR_DATA_LIST[one['Downstream']['sn']]['lat']))
    result = {}
    for RADAR_DATA in RADAR_DATA_LIST:
        # down_sn = {RADAR_DATA['sn'].split("_")[0] + str(int(RADAR_DATA['sn'].split("_")[1]) + 1)}
        RADAR_DATA['Downstream'] = {
            'sn': RADAR_DATA['sn'].split("_")[0] + "_" + str(int(RADAR_DATA['sn'].split("_")[1]) + 1)}
        RADAR_DATA['Upstream'] = {
            'sn': RADAR_DATA['sn'].split("_")[0] + "_" + str(int(RADAR_DATA['sn'].split("_")[1]) - 1)}
        RADAR_DATA['disDown'] = 1000
        RADAR_DATA['normal'] = True
        result[RADAR_DATA['sn']] = RADAR_DATA

    for k, v in result.items():
        if v['Downstream']['sn'] not in result.keys():
            result[k]['Downstream'] = None
        if v['Upstream']['sn'] not in result.keys():
            result[k]['Upstream'] = None
    print(result)
